//
//  CommentCell.m
//  LiveStar
//
//  Created by 漪珊 on 2017/5/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "CommentCell.h"

@implementation CommentCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor groupTableViewBackgroundColor];
        // contentLabel
        self.contentLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.contentLabel];
        self.contentLabel.backgroundColor  = [UIColor clearColor];
        self.contentLabel.preferredMaxLayoutWidth = [UIScreen mainScreen].bounds.size.width - kGAP-kAvatar_Size - 2*kGAP;
        
        self.contentLabel.numberOfLines = 0;
        self.contentLabel.font = [UIFont systemFontOfSize:14.0];
        
        [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.contentView.mas_left).offset(5);
            make.right.mas_equalTo(self.contentView.mas_right).offset(5);
            make.top.mas_equalTo(self.contentView).offset(3.0);//cell上部距离为3.0个间隙
        }];
        
        
        self.hyb_lastViewInCell = self.contentLabel;
        self.hyb_bottomOffsetToCell = 3.0;//cell底部距离为3.0个间隙
    }
    
    return self;
}

- (void)configCellWithModel:(CommentModel *)model {
    NSString *str  = nil;
    NSMutableAttributedString *text;
    if ([model.c_udid intValue] != [model.c_parudid intValue]) {
        str= [NSString stringWithFormat:@"%@回复%@：%@",
              model.cnickname, model.pnickname, model.c_content];
        
        text = [[NSMutableAttributedString alloc] initWithString:str];
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor orangeColor]
                     range:NSMakeRange(model.cnickname.length + 2, model.pnickname.length)];
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor orangeColor]
                     range:NSMakeRange(0, model.cnickname.length)];
    }else{
        str= [NSString stringWithFormat:@"%@：%@",
              model.cnickname, model.c_content];
        text = [[NSMutableAttributedString alloc] initWithString:str];
        [text addAttribute:NSForegroundColorAttributeName
                     value:[UIColor orangeColor]
                     range:NSMakeRange(0, model.cnickname.length)];
    }
    
    
    self.contentLabel.attributedText = text;
}

@end
